package so.wy.servicecenter.businessbed.web.order;

import com.github.binarywang.wxpay.bean.order.WxPayMpOrderResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import so.wy.servicecenter.base.exception.ServiceException;
import so.wy.servicecenter.base.exception.WebException;
import so.wy.servicecenter.base.frame.web.AbstractWeb;
import so.wy.servicecenter.base.frame.web.webhand.WebExceptionHandler;
import so.wy.servicecenter.businessbed.service.rent.OrderOptService;


@Service
@Scope("prototype")
public class OrderOptWeb extends AbstractWeb {
    @Autowired
    private OrderOptService orderOptService;

    @WebExceptionHandler
    public void finishOrder(Long userId,String orderSerial) throws WebException {
        try {
            orderOptService.finishOrder(userId, orderSerial);
        } catch (ServiceException e) {
            throw exception(e);
        }
    }

    @WebExceptionHandler
    public WxPayMpOrderResult payPreOrder(Long userId, String orderserial) throws WebException {
        try {
            return orderOptService.payPreOrder(userId, orderserial);
        } catch (ServiceException e) {
            throw exception(e);
        }
    }


    //人工免单
    @WebExceptionHandler
    public void freeOrder(Long userId,String orderSerial) throws WebException {
        try {
            orderOptService.freeOrder(userId, orderSerial);
        } catch (ServiceException e) {
            throw exception(e);
        }
    }

    //租赁
    @WebExceptionHandler
    public String rentDevice(Long userId, String deviceSerial) throws WebException {
        try {
          return   orderOptService.rentDevice(userId, deviceSerial);
        } catch (ServiceException e) {
            throw exception(e);
        }
    }

    @WebExceptionHandler
    public void rentError(Long userId, String orderSerial) throws WebException {
        try {
            orderOptService.rentError(userId, orderSerial);
        } catch (ServiceException e) {
            throw exception(e);
        }
    }

    //归还
    @WebExceptionHandler
    public void returnDevice(Long userId, String deviceSerial) throws WebException {
        try {
            orderOptService.returnDevice(userId, deviceSerial);
        } catch (ServiceException e) {
            throw exception(e);
        }
    }

}
